﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _3_3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入矩形长: ");
            double length = double.Parse(Console.ReadLine());

            Console.Write("请输入矩形宽: ");
            double width = double.Parse(Console.ReadLine());

            Rect rect = new Rect(length, width);
            Console.WriteLine($"解：矩形面积为{rect.GetArea()}，周长为{rect.GetPerimeter()}。");

            Console.WriteLine("\n---在此基础上构造矩体---\n");

            Console.Write("请输入矩体高: ");
            double height = double.Parse(Console.ReadLine());

            Cubold cubold = new Cubold(length, width, height);
            Console.WriteLine($"解：矩体表面积为{cubold.GetArea()}，体积为{cubold.GetVolume()}。");

            Console.Write("\n按任意键结束程序: ");
            Console.ReadKey();
        }
    }

    class Rect
    {
        protected double length, width;

        public Rect()
        {
            length = 0;
            width = 0;
        }

        public Rect(double l, double w)
        {
            length = l;
            width = w;
        }

        public virtual double GetArea()
        {
            return length * width;
        }

        public double GetPerimeter()
        {
            return 2 * (length + width);
        }
    }

    class Cubold : Rect
    {
        protected double height;

        public Cubold(double l, double w, double h) : base(l, w)
        {
            height = h;
        }

        public override double GetArea()
        {
            return 2 * (length * width + length * height + width * height);
        }

        public double GetVolume()
        {
            return length * width * height;
        }
    
}
    }

